      SUBROUTINE XACM(CMXO)
C
        IMPLICIT REAL*8 (A-H,O-Z)
      REAL * 8 MSUBM,MPX
      INTEGER*4 ACNTRL
C
      NAMELIST/ ATDCNT / SB,SAVEY,SAVET,TIME,TSTART,TX1,TR,TZ,TMX1,TMX2,
     .                   DT,DTA,MPX
C
C
      COMMON/CONSTS/ PI,TWOPI,RADIAN
C
      COMMON/CSTVAL/ TSTART,ZL0(10),ZL1(10),ZL2(10),ZLA(10)
C
      COMMON/DEBUG2/ IOUT,JOUT,KLUGE
C
      COMMON/MOMENT/ ACNTRL,IVISCS,IATTDE,IMGMTS,IWHEEL,NPULSE
C
      COMMON/OUTONE/ OMEGL,VSUBL,MSUBM(3),CMX1,SIMPX,SB
C
      COMMON/RATTDE/ DTMXA,PXI,PXO,EIT,REFTIM,TMX1,TMX2,CMX,ISW
C
      COMMON/RMAIN1/ DELTAT,FACTOR,FREQ,TSTOP,DELMIT,
     .               UPBND(150),DNBND(150)
C
      COMMON/RPOOL1/ RHOK(10),TIME,SA(3,3),FM1(3,3),ZLK(10),OMEG(3),
     .               ZLKP(10),ZLKDP(10),CMAT(3,3),GBAR(3,3),YBCM(3),
     .               ZBZK(3,10),FCM(3,3),DTO,PHID,PHI
C
      COMMON/RPOOL2/ PO,SD(3),DAN(3,10),DBN(3,10),CFMT(3,3),DIY1(3),
     .               SD1(3),DT1,P1,AERO,DTO1,YIZK(3),PO1
C
C
      DIMENSION SB(3)
C
C
C
C
C      TITLE
C
C        X BODY AXIS ATTITUDE CONTROL MOMENTS
C
C      PURPOSE
C
C        PROVIDE MEANS OF EXERTING ATTITUDE CONTROL MOMENTS ON X
C        BODY AXIS OF THE SPIN STABILIZED SATELLITE
C
C      INPUT ARGUEMENTS
C
C        DTXMA   TIME INCREMENT FROM TSTART WHEN THE TRANSVERSE ATTIT.
C                CONTROL SYSTEM IS ACTIVATED.
C        DTXMD   TIME INCREMENT FROM TSTART WHEN THE TRANSVERSE ATTIT.
C                CONTROL SYSTEM IS DEACTIVATED.     SECONDS
C
C        PXI     FRACTION OF SPIN PERIOD AFTER SUN LINE REFERENCE
C                POINT ESTABLISHED WHEN CONTROL TORQUE IS
C                APPLIED TO X BODY AXIS
C        PXO     FRACTION OF SPIN PERIOD AFTER SUN LINE REFERENCE
C                POINT ESTABLISHED WHEN CONTROL TORQUE IS REMOVED
C                FROM X BODY AXIS
C        EIT     TIME TOLERANCE FOR ACTIVATION AND DEACTIVATION OF
C                CONTROL MOMENTS, X AXIS     SECONDS
C        CMX     CONTROL MOMENT ALONG X BODY AXIS.
C                INPUT AS POSITIVE NUMBER MEANS MOMENT APPLIED ALONG
C                POSITIVE X BODY AXIS.   FT. LBS.
C
C      INPUT COMMON
C
C        TSTART  INITIAL PROBLEM TIME   SEC.
C        TIME    TIME OF PROBLEM REFERENCE TO TSTART  SEC.
C        SA      TRANSFORMATION MATRIX, BODY FRAME TO LOCAL
C                NON-ROTATING FRAME.
C        SD      UNIT VECTOR, SUN TO SATELLITE, EXPRESSED IN
C                LOCAL NON-ROTATING FRAME.
C     OMEG(3)    ANGULAR VELOCITY ABOUT THE Z BODY AXIS  RDNS/SEC.
C        DELTAT  TIME INCREMENT USED IN PROGRAM IN INTEGRATING
C                FROM POINT TO POINT
C
C      OUTPUT
C
C        SIMPX   A PARAMETER PROPORTIONAL TO TOTAL IMPULSE FOR CONTROL
C                MOMENTS APPLIED TO X BODY AXI@   FT. LB. SEC.
C        CMXO    OUTPUT CONTROL MOMENT ALONG X BODY AXIS
C        TR1     TIME AT REFERENCE POINT FOR EACH SPIN
C
C
C        INITIALIZE AT FIRST CALL ONLY
      IF(ISW.EQ.1) GO TO 30
      DT=0.0D0
      CMX1=0.0D0
      TMX1=0.0D0
      TMX2=0.0D0
      SAVET=0.0D0
      TX1=TIME + DTMXA
C
      DO 6 I=1,3
    6 SB(I)=0.D0
C
C
C        TEST FOR SYSTEM ACTIVATED PERIOD
   10 TR1=0.0D0
      TR=0.0D0
      TZ=0.0D0
      MPX=0
C
C        CALCULATE SUN SATELLITE VECTOR BODY COORDINATES
   30 DO 40 I=1,3
   40 SB(I)=0.0D0
      DO 50 I=1,3
      DO 50 J=1,3
   50 SB(I)=SD(J)*SA(J,I)+SB(I)
C
      CMXO=0.0D0
      IF(TIME-TX1) 110,51,51
   51 IF(TIME.GE.TMX1.AND.TIME.LE.TMX2) GO TO 105
C        DETECT CHANGE IN SIGN OF SB(2) AND LINEAR INTERPOLATE
      IF(ISW.EQ.0) GO TO 110
      TEMP=SAVEY*SB(2)
      IF(TEMP.GT.0.D0) GO TO 110
      IF(SB(1).GT.0.D0) GO TO 110
   56 TR=((-SAVEY*(TIME-SAVET))/(SB(2)-SAVEY))+SAVET
      ACNTRL=1
      IF(TMX1.NE.0.D0.AND.TMX2.NE.0.D0) GO TO 90
   85 TR1=TR
      TZ=TWOPI/DABS(OMEG(3))
      TMX1=TR+PXI*TZ
      TMX2=TR+PXO*TZ
   90 IF(TIME-TMX1-EIT) 110,100,100
  100 IF(TIME-TMX2+EIT) 105,105,110
C
C        ADD CONTROL MOMENT TO EXISTING MOMENTS
  105 CMXO=CMX
      CMX1=CMX
C
C
  110 REFTIM=TR1
C
      SAVEY=SB(2)
      SAVET=TIME
      ISW=1
      IF(IOUT.EQ.1) RETURN
      WRITE(6,ATDCNT)
      RETURN
      END
